/*
 * @Author       : NaN 353362604@qq.com
 * @Date         : 2023-05-09 10:05:16
 * @LastEditTime : 2023-06-15 16:25:30
 * @LastEditors  : NaN 353362604@qq.com
 * @FilePath     : \AdminStration\src\Pages\Front\Common\Template\QualityWarning.jsx
 * @Description  :
 */
import './Scss/QualityWarning.scss'

import dayjs from 'dayjs'
import { useEffect, useState } from 'react'
import { useMount, useRequest } from 'ahooks'
import { Http } from '../../../../Common/Api'
import { FrontModalBox } from '../Modal'

export const QualityWarning001 = ({ data, org }) => {
    const [Data, setData] = useState([])
    const [LabList, setLabList] = useState()
    const { run: getGetQualityCount } = useRequest(Http, {
        manual: true,
        onSuccess: res => {
            const { list } = res
            const [fraction] = list
            setData(Object.keys(data).map(key => ({ uuid: key, title: data[key], value: fraction[key] || 0 })))
        },
    })

    const { runAsync } = useRequest(Http, { manual: true, onSuccess: res => setLabList(res.labList) })

    useEffect(() => {
        getGetQualityCount({ url: `getGetQualityCount`, data: { organizationUuid: org || '' } })
    }, [getGetQualityCount, org])

    useMount(() => runAsync({ url: 'getQualityStatByOrg', data: { organizationUuid: org } }))
    const [OptionsCall, setOptionsCall] = useState()
    return (
        <div className="QualityWarning001">
            {Data.map(({ uuid, title, value }) => (
                <div
                    key={uuid}
                    onClick={() => {
                        if (uuid === 'labRowCounts' && LabList.length !== 0) {
                            setOptionsCall({
                                type: 'TableTest',
                                data: {
                                    title: '试验数据列表',
                                    uuid: org,
                                    LabList,
                                    startDate: dayjs().format('YYYY-MM') + '-01',
                                },
                            })
                        }
                        if (uuid === 'asphaltMixingStationDataRowCounts') {
                            setOptionsCall({
                                type: 'TableList',
                                data: {
                                    title: '沥青拌合站生产明细',
                                    type: 'GettAsphaltMixingStationDetail',
                                    uuid: org,
                                },
                            })
                        }
                        if (uuid === 'cementMixingStationDataRowCounts') {
                            setOptionsCall({
                                type: 'TableList',
                                data: {
                                    title: '水泥拌合站生产明细',
                                    type: 'CementMixingStationGroupDetail',
                                    uuid: org,
                                },
                            })
                        }
                    }}
                >
                    <div>{title}</div>
                    <div>{value}</div>
                </div>
            ))}
            <FrontModalBox OptionsCall={OptionsCall} />
        </div>
    )
}

export const QualityWarningA01 = ({ data, org }) => {
    const [Data, setData] = useState([])
    const [LabList, setLabList] = useState()

    const { runAsync } = useRequest(Http, {
        manual: true,
        onSuccess: res => {
            const { labList, list } = res
            const [fraction] = list
            console.log(labList)
            setLabList(labList)
            setData(Object.keys(data).map(key => ({ uuid: key, title: data[key], value: fraction[key] || 0 })))
        },
    })
    useMount(() => runAsync({ url: 'getQualityCount' }))

    const [OptionsCall, setOptionsCall] = useState()
    return (
        <div className="QualityWarning001">
            {Data.map(({ uuid, title, value }) => (
                <div
                    key={uuid}
                    onClick={() => {
                        if (uuid === 'labRowCounts' && LabList.length !== 0) {
                            setOptionsCall({
                                type: 'TableTest',
                                data: {
                                    title: '试验数据列表',
                                    uuid: org,
                                    LabList,
                                    startDate: dayjs().format('YYYY-MM') + '-01',
                                },
                            })
                        }
                        if (uuid === 'asphaltMixingStationDataRowCounts') {
                            setOptionsCall({
                                type: 'TableList',
                                data: {
                                    title: '沥青拌合站生产明细',
                                    type: 'GettAsphaltMixingStationDetail',
                                    uuid: org,
                                },
                            })
                        }
                        if (uuid === 'cementMixingStationDataRowCounts') {
                            setOptionsCall({
                                type: 'TableList',
                                data: {
                                    title: '水泥拌合站生产明细',
                                    type: 'CementMixingStationGroupDetail',
                                    uuid: org,
                                },
                            })
                        }
                    }}
                >
                    <div>{title}</div>
                    <div>{value}</div>
                </div>
            ))}
            <FrontModalBox OptionsCall={OptionsCall} />
        </div>
    )
}
